package com.bw1806.sellergoods.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.bw1806.mapper.TbGoodsDescMapper;
import com.bw1806.pojo.TbGoodsDesc;
import com.bw1806.pojo.TbGoodsDescExample;
import com.bw1806.sellergoods.service.TbGoodsDescService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2020/11/1115:02
 */
@Service(timeout = 5000,retries = 0)
public class TbGoodsDescServiceImpl implements TbGoodsDescService {

    @Autowired
    private TbGoodsDescMapper tbGoodsDescMapper;

    @Override
    public List<TbGoodsDesc> findAll() {
        return tbGoodsDescMapper.selectByExample(null);
    }

    @Override
    public PageResult<TbGoodsDesc> pagelist(TbGoodsDesc tbGoodsDesc,int pageNum,int pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        TbGoodsDescExample example=new TbGoodsDescExample();

        TbGoodsDescExample.Criteria criteria = example.createCriteria();

        if(tbGoodsDesc!=null){
            //if(tbGoodsDesc.getName()!=null && tbGoodsDesc.getName().length()>0){
            //    criteria.andNameLike("%"+tbGoodsDesc.getName()+"%");
           // }
        }

        Page<TbGoodsDesc> page= (Page<TbGoodsDesc>) tbGoodsDescMapper.selectByExample(example);

        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public void save(TbGoodsDesc tbGoodsDesc) {
        Long id = tbGoodsDesc.getGoodsId();
        if(id != null && id !=0){
            tbGoodsDescMapper.updateByPrimaryKey(tbGoodsDesc);
        } else{
            tbGoodsDescMapper.insert(tbGoodsDesc);
        }
    }

    @Override
    public TbGoodsDesc getById(Long id) {
        return tbGoodsDescMapper.selectByPrimaryKey(id);
    }

    @Override
    public void deletebth(Long[] ids) {
       for(long id : ids){
            tbGoodsDescMapper.deleteByPrimaryKey(id);
        }
        //tbGoodsDescMapper.deletebth(ids);
    }
}
